﻿#include "answeritem.h"

answeritem::answeritem(QString qlabel,QStringList answers)
{
    this->m_num=0;
    this->score=0;
    this->m_qlabel=qlabel;
    this->m_answers=answers;

    isSigned=true;
    if(answers.size()>1)
    {
        isSigned=false;
    }
}

answeritem::answeritem()
{
    this->m_num=0;
    this->score=0;
}

answeritem::answeritem(const answeritem &ai)
{
    this->m_num=0;
    this->m_qlabel=ai.m_qlabel;
    this->m_answers=ai.m_answers;
    for(int i=0;i<ai.m_items.size();i++)
    {
        this->setItems(ai.m_items[i].first);
    }

}

answeritem answeritem::operator=(const answeritem &ai)
{
    this->m_num=0;
    this->m_qlabel=ai.m_qlabel;
    this->m_answers=ai.m_answers;
    for(int i=0;i<ai.m_items.size();i++)
    {
        this->setItems(ai.m_items[i].first);
    }
    return *this;
}

answeritem::~answeritem()
{

}

QString answeritem::getLabel() const
{
    return m_qlabel;
}

bool answeritem::setItems(QString item)
{
    for(int i=0;i<m_items.size();i++)
    {
        if(m_items[i].first==item)
        {
            return false;
        }
    }
    this->m_items.append(QPair<QString,int>(item,0));
    m_num++;
    return true;
}

QVector<QPair<QString, int> > &answeritem::getItems()
{
    return this->m_items;
}

void answeritem::setScore(int score)
{
    this->score=score;
}

int answeritem::getScore() const
{
    return this->score;
}

unsigned answeritem::getNum() const
{
    return m_num;
}

bool answeritem::getIsSigned() const
{
    return isSigned;
}

QStringList answeritem::getAnswers() const
{
    return this->m_answers;
}
